package com.sz.app.customer.api.base;

import com.sz.biz.app.web.BaseController;
import com.sz.biz.common.base.service.SettlementTypeService;
import com.sz.common.base.dto.QueryParams;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.base.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Function: 结算方式 controller <br>
 * Author: hpeng.wang <br>
 * Date: 2016-11-25 11:08:00
 */

@RestController
@RequestMapping("${api}/biz/settypes")
@Api(description = " ", tags = "023、结算方式管理")
public class SettlementTypeController extends BaseController {
    @Autowired
    private SettlementTypeService service;

    /**
     * 根据条件获取数据集合
     *
     * @param q         参数信息
     * @param pageIndex 哪页
     * @param pageSize  分页大小
     * @param sort      排序字段的名称
     * @param asc       true asc false desc
     * @return 查询的数据集合
     */
    @ApiOperation(value = "查询", notes = "根据指定条件获取数据集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "q", value = "模糊查询参数", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query", defaultValue
                    = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数,max<2000", dataType = "int", paramType = "query",
                    defaultValue = "10"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query", defaultValue =
                    "true")
    })

    @RequestMapping(value = "", method = RequestMethod.GET)
    public ResultDto findByParam(@RequestParam(required = false) String q,
                                 @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                 @RequestParam(required = false, defaultValue = "10") int pageSize,
                                 @RequestParam(required = false) String sort,
                                 @RequestParam(required = false, defaultValue = "true") Boolean asc) throws Exception {
        q = StringUtils.replaceSqlPattern(q);
        ResultDto resultDto = service.findByParam(new QueryParams(pageSize, pageIndex, q, sort, asc));
        return resultDto;
    }


}
